
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections;

using Swaf;

namespace Swaf.Crypto
{
	/// <summary>
	/// Summary description for BaseKeyMaster.
	/// </summary>
	public abstract class BaseKeyMaster : IKeyMaster
	{
		private IDictionary m_activeHandlers = new Hashtable();
		static private IClassFactory s_cryptoHandlerFactory = null;

		public BaseKeyMaster()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		static protected internal IClassFactory CryptoHandlerFactory
		{
			get
			{
				if(s_cryptoHandlerFactory == null)
					s_cryptoHandlerFactory = Application.currentApp.factories["CryptoHandlers"];
				return s_cryptoHandlerFactory;
			}
		}

		protected internal ICryptoHandler getHandler(string name)
		{
			ICryptoHandler handler = (ICryptoHandler)m_activeHandlers[name];
			if(handler == null)
			{
				handler = (ICryptoHandler)CryptoHandlerFactory.createFromNickName(name);
				m_activeHandlers[name] = handler;
			}

			return handler;
		}

		#region IKeyMaster Members
		public abstract void removeKeyInfo(string name, bool persist);
		public abstract IKeyInfo getKeyInfo(string name);
		public abstract void generateKeyInfo(string name, string type, bool persist);
		public abstract void generateKeyInfo(string name, string type, int numRandomKeys, bool persist);
		public abstract IDictionary Keys{get;}
		#endregion
	}
}
